#This plot produces Figure S5 in the Supplemental Appendix

setwd("/Users/bsjjones/Dropbox/JoestenJones/PB R&R")

library(foreign)
library(rmeta)
library(plotrix)

####THIS SCRIPT GIVES PLACEBO MODELS#####
 
#################################################################
#Robustness Check Plots##########################################
#Gay Marriage, Health Care, Tax Policy###########################
pdf("figureS5_Rplot.pdf", width=7, height=7)
par(mfrow=c(3,3),oma=c(0,0,2,0))
par(mar=c(3, 3, 2, 2))
#par(mar=c(2, 4, 1, 1))


###Gay Marriage###


g7nd<-read.dta("gay7nd.dta")
attach(g7nd)
coef.vec<-pr1
se.vec<-se
x.axis<-c(length(coef.vec):1)
#var.names<-label
emph<-seq(-1, 1, .1)

g7nnd<-read.dta("gay7nnd.dta")
attach(g7nnd)
coef.vec2<-pr1
se.vec2<-se
x.axis2<-c(length(coef.vec):1)
#var.names<-label
emph2<-seq(-1, 1, .1)


plotCI(emph, coef.vec, 1.96*se.vec,  1.96*se.vec, lwd = 1, col = "black", scol = "black", lty=1, axes = TRUE, xlab = "Republican Priority: Gay Marriage", ylab = "Man and Woman", pch = 20, cex.axis = .65, main = "A. Gay Marriage and GOP Priority", cex.main=.95, cex.lab=.85, mgp=c(2,.7,0), ylim=c(0,1), xaxt="n")
axis(1, at=c(-1, 0, 1), labels=c("Low", "Average", "High"), cex.axis=.65)

lines(emph, coef.vec, type="l", col="black")

 
par(new=TRUE)

plotCI(emph2, coef.vec2, 1.96*se.vec2,  1.96*se.vec2, lwd = 1, col = "gray50", scol = "gray50", ylim=c(0,1), ylab="", xlab="", pch= 20, axes=F)
lines(emph2, coef.vec2, type="l", col="gray50")


legend("topleft", c("New Destination", "Non-New Destination"), lty=c(1,1), lwd=c(1,1), col=c("black", "gray50"), bty="n", cex=.65)


rm(list=ls())
detach(g7nd)
detach(g7ndd)



###Health Care#####

h7nd<-read.dta("health7nd.dta")
attach(h7nd)
coef.vec<-pr1
se.vec<-se
x.axis<-c(length(coef.vec):1)
#var.names<-label
emph<-seq(-1, 1, .1)

h7nnd<-read.dta("health7nnd.dta")
attach(h7nnd)
coef.vec2<-pr1
se.vec2<-se
x.axis2<-c(length(coef.vec):1)
#var.names<-label
emph2<-seq(-1, 1, .1)



plotCI(emph, coef.vec, 1.96*se.vec,  1.96*se.vec, lwd = 1, col = "black", scol = "black", lty=1, axes = TRUE, xlab = "Republican Priority: Health Care", ylab = "Repeal Health Care", pch = 20, cex.axis = .65, main = "B. Health Care and GOP Priority", cex.main=.95, cex.lab=.85, mgp=c(2,.7,0), ylim=c(0,1), xaxt="n")
axis(1, at=c(-1, 0, 1), labels=c("Low", "Average", "High"), cex.axis=.65)
lines(emph, coef.vec, type="l", col="black")

 
par(new=TRUE)

plotCI(emph2, coef.vec2, 1.96*se.vec2,  1.96*se.vec2, lwd = 1, col = "gray50", scol = "gray50", ylim=c(0,1), ylab="", xlab="", pch= 20, axes=F)
lines(emph2, coef.vec2, type="l", col="gray50")


legend("topleft", c("New Destination", "Non-New Destination"), lty=c(1,1), lwd=c(1,1), col=c("black", "gray50"), bty="n", cex=.65)

rm(list=ls())
detach(h7nd)
detach(h7nnd)


###Tax Issue#####

t7nd<-read.dta("tax7nd.dta")
attach(t7nd)
coef.vec<-pr1
se.vec<-se
x.axis<-c(length(coef.vec):1)
#var.names<-label
emph<-seq(-1, 1, .1)

t7nnd<-read.dta("tax7nnd.dta")
attach(t7nnd)
coef.vec2<-pr1
se.vec2<-se
x.axis2<-c(length(coef.vec):1)
#var.names<-label
emph2<-seq(-1, 1, .1)

plot(emph, coef.vec, type = "o", lty=1, axes = TRUE, xlab = "Republican Priority: Taxes", ylab = "No Taxes", pch = 20, cex.axis = .65, main = "C. Tax Policy and GOP Priority", cex.main=.95, cex.lab=.85, mgp=c(2,.7,0), ylim=c(0,1), col="black", xaxt="n")
segments(emph, coef.vec-qnorm(.975)*se.vec, emph, coef.vec+qnorm(.975)*se.vec, lwd =  1, col="black")
lines(emph2, coef.vec2, type = "o", pch=20, lty=1, ylim=c(0,1), col="gray50")
segments(emph2, coef.vec2-qnorm(.975)*se.vec2, emph2, coef.vec2+qnorm(.975)*se.vec2, lwd =  1, col="gray50")
axis(1, at=c(-1, 0, 1), labels=c("Low", "Average", "High"), cex.axis=.65)
legend("topleft", c("New Destination", "Non New Destination"), lty=c(1,1), lwd=c(1,1), col=c("black", "gray50"), bty="n", cex=.65)


rm(list=ls())
detach(t7nd)
detach(t7ndd)

################Immigration as a function of Priorities on Other Issues###########
###Gay Marriage and Immigration###


g7nd<-read.dta("gayimm7nd.dta")
attach(g7nd)
coef.vec<-pr1
se.vec<-se
x.axis<-c(length(coef.vec):1)
#var.names<-label
emph<-seq(-1, 1, .1)

g7nnd<-read.dta("gayimm7nnd.dta")
attach(g7nnd)
coef.vec2<-pr1
se.vec2<-se
x.axis2<-c(length(coef.vec):1)
#var.names<-label
emph2<-seq(-1, 1, .1)


plotCI(emph, coef.vec, 1.96*se.vec,  1.96*se.vec, lwd = 1, col = "black", scol = "black", lty=1, axes = TRUE, xlab = "Republican Priority: Gay Marriage", ylab = "Forcible Return", pch = 20, cex.axis = .65, main = "D. Immigration and Gay Marriage", cex.main=.95, cex.lab=.85, mgp=c(2,.7,0), ylim=c(0,1), xaxt="n")
axis(1, at=c(-1, 0, 1), labels=c("Low", "Average", "High"), cex.axis=.65)
lines(emph, coef.vec, type="l", col="black")

 
par(new=TRUE)

plotCI(emph2, coef.vec2, 1.96*se.vec2,  1.96*se.vec2, lwd = 1, col = "gray50", scol = "gray50", ylim=c(0,1), ylab="", xlab="", pch= 20, axes=F)
lines(emph2, coef.vec2, type="l", col="gray50")


legend("topleft", c("New Destination", "Non-New Destination"), lty=c(1,1), lwd=c(1,1), col=c("black", "gray50"), bty="n", cex=.65)


rm(list=ls())
detach(g7nd)
detach(g7ndd)



#####Health Care and Immigration######

g7nd<-read.dta("healthimm7nd.dta")
attach(g7nd)
coef.vec<-pr1
se.vec<-se
x.axis<-c(length(coef.vec):1)
#var.names<-label
emph<-seq(-1, 1, .1)

g7nnd<-read.dta("healthimm7nnd.dta")
attach(g7nnd)
coef.vec2<-pr1
se.vec2<-se
x.axis2<-c(length(coef.vec):1)
#var.names<-label
emph2<-seq(-1, 1, .1)


plotCI(emph, coef.vec, 1.96*se.vec,  1.96*se.vec, lwd = 1, col = "black", scol = "black", lty=1, axes = TRUE, xlab = "Republican Priority: Health Care", ylab = "Forcible Return", pch = 20, cex.axis = .65, main = "E. Immigration and Health Care", cex.main=.95, cex.lab=.85, mgp=c(2,.7,0), ylim=c(0,1), xaxt="n")
axis(1, at=c(-1, 0, 1), labels=c("Low", "Average", "High"), cex.axis=.65)
lines(emph, coef.vec, type="l", col="black")

 
par(new=TRUE)

plotCI(emph2, coef.vec2, 1.96*se.vec2,  1.96*se.vec2, lwd = 1, col = "gray50", scol = "gray50", ylim=c(0,1), ylab="", xlab="", pch= 20, axes=F)
lines(emph2, coef.vec2, type="l", col="gray50")


legend("topleft", c("New Destination", "Non-New Destination"), lty=c(1,1), lwd=c(1,1), col=c("black", "gray50"), bty="n", cex=.65)


rm(list=ls())
detach(g7nd)
detach(g7ndd)


##########Tax Policy#############

g7nd<-read.dta("taximm7nd.dta")
attach(g7nd)
coef.vec<-pr1
se.vec<-se
x.axis<-c(length(coef.vec):1)
#var.names<-label
emph<-seq(-1, 1, .1)

g7nnd<-read.dta("taximm7nnd.dta")
attach(g7nnd)
coef.vec2<-pr1
se.vec2<-se
x.axis2<-c(length(coef.vec):1)
#var.names<-label
emph2<-seq(-1, 1, .1)


plotCI(emph, coef.vec, 1.96*se.vec,  1.96*se.vec, lwd = 1, col = "black", scol = "black", lty=1, axes = TRUE, xlab = "Republican Priority: Taxes", ylab = "Forcible Return", pch = 20, cex.axis = .65, main = "F. Immigration and Taxes", cex.main=.95, cex.lab=.85, mgp=c(2,.7,0), ylim=c(0,1), xaxt="n")
axis(1, at=c(-1, 0, 1), labels=c("Low", "Average", "High"), cex.axis=.65)
lines(emph, coef.vec, type="l", col="black")

 
par(new=TRUE)

plotCI(emph2, coef.vec2, 1.96*se.vec2,  1.96*se.vec2, lwd = 1, col = "gray50", scol = "gray50", ylim=c(0,1), ylab="", xlab="", pch= 20, axes=F)
lines(emph2, coef.vec2, type="l", col="gray50")


legend("topleft", c("New Destination", "Non-New Destination"), lty=c(1,1), lwd=c(1,1), col=c("black", "gray50"), bty="n", cex=.65)


rm(list=ls())
detach(g7nd)
detach(g7ndd)


################Other issues as a function of Priorities on Immigration###########
###Gay Marriage and Immigration###


g7nd<-read.dta("Dgayimm7nd.dta")
attach(g7nd)
coef.vec<-pr1
se.vec<-se
x.axis<-c(length(coef.vec):1)
#var.names<-label
emph<-seq(-1, 1, .1)

g7nnd<-read.dta("Dgayimm7nnd.dta")
attach(g7nnd)
coef.vec2<-pr1
se.vec2<-se
x.axis2<-c(length(coef.vec):1)
#var.names<-label
emph2<-seq(-1, 1, .1)


plotCI(emph, coef.vec, 1.96*se.vec,  1.96*se.vec, lwd = 1, col = "black", scol = "black", lty=1, axes = TRUE, xlab = "Republican Priority: Immigration", ylab = "Man and Woman", pch = 20, cex.axis = .65, main = "G. Gay Marriage and Immigration", cex.main=.95, cex.lab=.85, mgp=c(2,.7,0), ylim=c(0,1), xaxt="n")
axis(1, at=c(-1, 0, 1), labels=c("Low", "Average", "High"), cex.axis=.65)
lines(emph, coef.vec, type="l", col="black")

 
par(new=TRUE)

plotCI(emph2, coef.vec2, 1.96*se.vec2,  1.96*se.vec2, lwd = 1, col = "gray50", scol = "gray50", ylim=c(0,1), ylab="", xlab="", pch= 20, axes=F)
lines(emph2, coef.vec2, type="l", col="gray50")


legend("topleft", c("New Destination", "Non-New Destination"), lty=c(1,1), lwd=c(1,1), col=c("black", "gray50"), bty="n", cex=.65)


rm(list=ls())
detach(g7nd)
detach(g7ndd)



#####Health Care and Immigration######

g7nd<-read.dta("Dhealthimm7nd.dta")
attach(g7nd)
coef.vec<-pr1
se.vec<-se
x.axis<-c(length(coef.vec):1)
#var.names<-label
emph<-seq(-1, 1, .1)

g7nnd<-read.dta("Dhealthimm7nnd.dta")
attach(g7nnd)
coef.vec2<-pr1
se.vec2<-se
x.axis2<-c(length(coef.vec):1)
#var.names<-label
emph2<-seq(-1, 1, .1)


plotCI(emph, coef.vec, 1.96*se.vec,  1.96*se.vec, lwd = 1, col = "black", scol = "black", lty=1, axes = TRUE, xlab = "Republican Priority: Immigration", ylab = "Repeal Health Care", pch = 20, cex.axis = .65, main = "H. Health Care and Immigration", cex.main=.95, cex.lab=.85, mgp=c(2,.7,0), ylim=c(0,1), xaxt="n")
axis(1, at=c(-1, 0, 1), labels=c("Low", "Average", "High"), cex.axis=.65)
lines(emph, coef.vec, type="l", col="black")

 
par(new=TRUE)

plotCI(emph2, coef.vec2, 1.96*se.vec2,  1.96*se.vec2, lwd = 1, col = "gray50", scol = "gray50", ylim=c(0,1), ylab="", xlab="", pch= 20, axes=F)
lines(emph2, coef.vec2, type="l", col="gray50")


legend("topleft", c("New Destination", "Non-New Destination"), lty=c(1,1), lwd=c(1,1), col=c("black", "gray50"), bty="n", cex=.65)


rm(list=ls())
detach(g7nd)
detach(g7ndd)


##########Tax Policy#############

g7nd<-read.dta("Dtaximm7nd.dta")
attach(g7nd)
coef.vec<-pr1
se.vec<-se
x.axis<-c(length(coef.vec):1)
#var.names<-label
emph<-seq(-1, 1, .1)

g7nnd<-read.dta("Dtaximm7nnd.dta")
attach(g7nnd)
coef.vec2<-pr1
se.vec2<-se
x.axis2<-c(length(coef.vec):1)
#var.names<-label
emph2<-seq(-1, 1, .1)


plotCI(emph, coef.vec, 1.96*se.vec,  1.96*se.vec, lwd = 1, col = "black", scol = "black", lty=1, axes = TRUE, xlab = "Republican Priority: Immigration", ylab = "No Taxes", pch = 20, cex.axis = .65, main = "I. Taxes and Health Care", cex.main=.95, cex.lab=.85, mgp=c(2,.7,0), ylim=c(0,1), xaxt="n")
axis(1, at=c(-1, 0, 1), labels=c("Low", "Average", "High"), cex.axis=.65)
lines(emph, coef.vec, type="l", col="black")

 
par(new=TRUE)

plotCI(emph2, coef.vec2, 1.96*se.vec2,  1.96*se.vec2, lwd = 1, col = "gray50", scol = "gray50", ylim=c(0,1), ylab="", xlab="", pch= 20, axes=F)
lines(emph2, coef.vec2, type="l", col="gray50")


legend("topleft", c("New Destination", "Non-New Destination"), lty=c(1,1), lwd=c(1,1), col=c("black", "gray50"), bty="n", cex=.65)
title("Republican Cues, Context and Other Campaign Issues",  outer=TRUE)



rm(list=ls())
detach(g7nd)
detach(g7ndd)
dev.off()